<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="../../node_modules/jquery/dist/jquery.js"></script>
</head>

<body>

<form id="uploadForm">
    <input id="fileContent" type="file" name="upLoadFile"/>
    <button id="fileButton" type="button">Submit</button>
</form>


<script>
    document.getElementById("fileButton").addEventListener("click",()=>{
        let fileElement = document.getElementById("fileContent");
        let fileObject = fileElement.files[0]
         let formData = new FormData();
        formData.append("file", fileObject)
        $.ajax({
            url: '/user/upload',
            type: 'POST',
            cache: false,    //上传文件不需要缓存
            data: formData,
            processData: false, // 告诉jQuery不要去处理发送的数据
            contentType: false, // 告诉jQuery不要去设置Content-Type请求头
            success: function (res) {

                if(res.ret == 0){
                    alert("上传成功")
                }
            },
            error: function (err) {
            }
        })
    })




</script>
</body>

</html>